00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00051 require_once (PATH_TO_ROOT."roleplay/classes/class.role.inc.php");
00052 require_once (PATH_TO_ROOT."teams/classes/class.team.inc.php");
00066 function getPictureLink($userID, $w, $h) {
00067 if ($userID > 0) {
00068 global $settings, $db, $EZSQL_ERROR;
00069 $userHomepageData = $db->get_row("SELECT picture, Vorname, Nachname FROM user WHERE ID = ".$userID);
00070 if (!$db->num_rows) return false;
00071 $picture = $userHomepageData->picture;
00072 $userName = Data::toHTML("$userHomepageData->Vorname $userHomepageData->Nachname", false);
00073
00074 $uploadDir = PATH_TO_ROOT.$settings['upload_path'];
00075 if ($picture) {
00076 $picPath = $uploadDir."user/".$userID."/";
00077 $picLink = $picPath.$picture;
00078 $is_picture = is_file($picLink);
00079 if ($is_picture) {
00080 $picLink = rawurlencode($picLink);
00081 $picLink = PATH_TO_ROOT."common/makethumb.php?picurl=$picLink&maxw=$w&maxh=$h";
00082 $picturePath = '<img src="'.$picLink.'" alt="Avatar von '.$userName.'" title="Avatar von '.$userName.'" />';
00083 return $picturePath;
00084 } else {
00085 return false;
00086 }
00087 } else {
00088 return false;
00089 }
00090 } else {
00091 return false;
00092 }
00093 }
00094
00100 function flag_make_array($str) {
00101 $a = array();
00102 $strlen = strlen($str);
00103 for ($i = 0 ; $i < $strlen ; $i++) {
00104 $a[] = $str[$i];
00105 }
00106 return $a;
00107 }
00108
00115 function flag_or($str1, $str2) {
00116 $str = "";
00117 $max = max(strlen($str1), strlen($str2));
00118 for ($i = 0 ; $i < $max ; $i++) {
00119 if (($i < strlen($str1) && $str1[$i]) || ($i < strlen($str2) && $str2[$i])) {
00120 $str.= "1";
00121 } else {
00122 $str.= "0";
00123 }
00124 }
00125 return $str;
00126 }
00127
00134 function build_link($link, $noamp = false) {
00135 global $g_user, $s;
00136 $add = '';
00137 if ($g_user['userID'] != 0) {
00138 if ($x = strpos($link, "#")) {
00139 $link = substr($link, 0, $x) .$add.substr($link, $x);
00140 } else {
00141 $link.= $add;
00142 }
00143 }
00144 return $link;
00145 }
00146
00152 class Template {
00153
00159 function Template($szTemplateName) {
00160 if (!file_exists($szTemplateName)) {
00161 $this->Halt("Unable to load template file: '".$szTemplateName."' does not exist.");
00162 }
00163 $this->szTemplateData = @implode('', (@file($szTemplateName)));
00164 $this->szTemplateData = str_replace('"', '\"', $this->szTemplateData);
00165 $this->szTemplateData = preg_replace("/_\('([^']+)'\)/", '".build_link("$1")."', $this->szTemplateData);
00166 }
00167
00173 function GetTemplate($szVarname = "") {
00174 if ($szVarname) {
00175 return ('if (!isset($'.$szVarname.')) $'.$szVarname.' = ""; $'.$szVarname.' .= "'.$this->szTemplateData.'";');
00176 } else {
00177 return ('compress_page("'.$this->szTemplateData.'");');
00178 }
00179 }
00180
00186 function Halt($szErrorMsg) {
00187 echo "<pre>Template error:\n ".$szErrorMsg."</pre>";
00188 exit;
00189 }
00190 }
00191
00192
00193
00194 class Permission {
00195 var $a_group;
00196 var $a_groupboard;
00197 var $boardid;
00198 var $invisible;
00199
00207 function Permission($groupids, $boardid = -1, $invisible = 0) {
00208 if ($groupids === '') $groupids = '-1';
00209 $this->a_group = array();
00210 $r_group = forum_query("SELECT groupid, accessmask FROM forum_group WHERE groupid IN(".$groupids.")");
00211 while ($group = mysql_fetch_array($r_group)) {
00212 $this->a_group[$group['groupid']] = $group['accessmask'];
00213 }
00214 mysql_free_result($r_group);
00215 $this->a_groupboard = array();
00216 if ($boardid == -1) $r_groupboard = forum_query("SELECT groupid, boardid, accessmask FROM forum_groupboard WHERE groupid IN (".$groupids.")");
00217 else $r_groupboard = forum_query("SELECT groupid, boardid, accessmask FROM forum_groupboard WHERE boardid='$boardid' AND groupid IN (".$groupids.")");
00218 while ($groupboard = mysql_fetch_array($r_groupboard)) {
00219 $this->a_groupboard[$groupboard['boardid']][$groupboard['groupid']] = $groupboard['accessmask'];
00220 }
00221 mysql_free_result($r_groupboard);
00222 $this->set_boardid($boardid);
00223 $this->invisible = $invisible;
00224 }
00225
00231 function set_boardid($boardid) {
00232 $this->boardid = $boardid;
00233 }
00234
00240 function has_permission($perm) {
00241 if ($this->invisible && ($perm == P_POSTNEW || $perm == P_REPLY) && !isset($this->a_group[3])) return false;
00242 $mask = "";
00243 reset($this->a_group);
00244 reset($this->a_groupboard);
00245 while (list($groupid, $accessmask) = each($this->a_group)) {
00246 if (isset($this->a_groupboard[$this->boardid][$groupid])) {
00247 $mask = flag_or($mask, $this->a_groupboard[$this->boardid][$groupid]);
00248 } else {
00249 $mask = flag_or($mask, $accessmask);
00250 }
00251 }
00252 if (strlen($mask) < $perm) {
00253 return false;
00254 }
00255 $access = flag_make_array($mask);
00256 return isset($access[$perm]) && (bool)($access[$perm]);
00257 }
00258 }
00259
00265 function requires_permission($perm) {
00266 global $g_user, $config, $options, $P, $_SERVER, $DEBUG, $debug, $titleprepend, $CONTENT, $settings;
00267 if ($P->has_permission($perm)) return;
00268 global $board;
00269 if (!isset($navpath) || !$navpath) {
00270 $navpath = '<a href="'.build_link("index.php") .'" title="Fehler: Zugriff verweigert."></a> » Zugriff verweigert';
00271 } elseif (substr($navpath, strlen($navpath) -8) != "» ") {
00272 $navpath.= " » Zugriff verweigert";
00273 }
00274 $Tframe = new Template("templates/frame.html");
00275 $Tnopermission = new Template("templates/nopermission.html");
00276 $t_loginform = '';
00277 if (!$g_user['userID']) {
00278 $Tnoperm_login = new Template("templates/noperm_login.html");
00279 $source = urlencode(basename($_SERVER['REQUEST_URI']));
00280 eval($Tnoperm_login->GetTemplate('t_loginform'));
00281 }
00282 eval($Tnopermission->GetTemplate("CONTENT"));
00283 eval($Tframe->GetTemplate());
00284 include_once PATH_TO_ROOT."forum/footer.inc.php";
00285 require_once (PATH_TO_ROOT."common/footer.inc.php");
00286 exit;
00287 }
00288 define('INVALID_CHAR', 1);
00289 define('INVALID_LENGTH', 2);
00290 define('NAME_TAKEN', 3);
00291 define('NAME_BANNED', 4);
00292
00293
00294
00300 function check_email($email) {
00301 return eregi("^[\_a-z0-9-]+(\.[\_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", $email);
00302 }
00303
00304
00313 function message($title, $msg, $opt_back = 1, $opt_index = 1) {
00314 global $settings;
00315 echo "<br/><br/><table width='100%' style='text-align: center;'>";
00316 Output::echoMessage($msg);
00317 echo "</table><br/><br/>";
00318 include_once PATH_TO_ROOT."forum/footer.inc.php";
00320 require_once (PATH_TO_ROOT."common/footer.inc.php");
00321 exit;
00322 }
00323
00332 function errormessage($title = '', $msg, $opt_back = 1, $opt_index = 1) {
00333 global $settings;
00334 echo "<br/><br/><table width='100%' style='text-align: center;'>";
00335 Output::errorMessage($msg);
00336 echo "</table><br/><br/>";
00337 include_once PATH_TO_ROOT."forum/footer.inc.php";
00339 require_once (PATH_TO_ROOT."common/footer.inc.php");
00340 exit;
00341 }
00342
00349 function message_redirect($msg, $url) {
00350 global $settings;
00351 $TRedirect = new Template('templates/redirect.html');
00352 eval($TRedirect->GetTemplate());
00353 include_once PATH_TO_ROOT."forum/footer.inc.php";
00355 require_once (PATH_TO_ROOT."common/footer.inc.php");
00356 exit;
00357 }
00358
00359
00360 function form_date($time, $verbose = 1) {
00361 global $config;
00362 if ($time < (60*60*24)) {
00363 return "N/A";
00364 }
00365 $time+= $config['timeoffset']*3600;
00366 if (date("d.m.Y", (time() +$config['timeoffset']*3600)) == date('d.m.Y', $time) && $verbose) {
00367 return "<strong>Heute</strong>, ".Output::echoDate("H:i", (int)$time);
00368 } else {
00369 return Output::echoDate("d.m.Y, H:i", (int)$time);
00370
00371 }
00372 }
00373
00374 function r_stripslashes(&$array) {
00375 while (list($k, $v) = each($array)) {
00376 if ($k != 'argc' && $k != 'argv' && (strtoupper($k) != $k || ''.intval($k) == "$k")) {
00377 if (is_string($v)) {
00378 $array[$k] = stripslashes($v);
00379 }
00380 if (is_array($v)) {
00381 $array[$k] = r_stripslashes($v);
00382 }
00383 }
00384 }
00385 return $array;
00386 }
00387 function jumpmenu($currentboard = 1) {
00388 global $g_user;
00389 $P = new Permission($g_user['groupids']);
00390
00391 $a_board = array();
00392 $r_board = forum_query("SELECT boardid, boardname, categoryid
00393 FROM forum_board
00394 WHERE boarddisabled=0 AND is_photogallery=1
00395 ORDER BY boardorder ASC");
00396 while ($board = mysql_fetch_array($r_board)) {
00397 $P->set_boardid($board['boardid']);
00398 if ($P->has_permission(P_VIEW)) $a_board[$board['categoryid']][] = $board;
00399 }
00400
00401 $r_category = forum_query("SELECT categoryid, categoryname FROM
00402 forum_category ORDER BY categoryorder ASC");
00403 $JUMP_MENU = '<select class="tbselect" name="board[boardid]" onchange="Submit.click()">';
00404 while ($category = mysql_fetch_array($r_category)) {
00405 if (!empty($a_board[$category['categoryid']]) && $a_board[$category['categoryid']]) {
00406 $JUMP_MENU.= '<option value="-'.$category['categoryid'].'">'.$category['categoryname'].'</option>';
00407 while (list(, $board) = each($a_board[$category['categoryid']])) {
00408 $JUMP_MENU.= '<option value="'.$board['boardid'].'"'.($board['boardid'] == $currentboard ? ' selected="selected"' : '') .'>- '.$board['boardname'].'</option>';
00409 }
00410 }
00411 }
00412 $JUMP_MENU.= '</select> <p class="pForm"><input class="tbbutton" type="submit" name="Submit" value="Jump"/></p>';
00413 return $JUMP_MENU;
00414 }
00415 function forum_array_reverse($array) {
00416 if (function_exists('array_reverse')) {
00417 return array_reverse($array);
00418 } else {
00419 $a_new = array();
00420 $count = count($array) -1;
00421 for ($i = $count ; $i >= 0 ; $i--) {
00422 $a_new[] = $array[$i];
00423 }
00424 return $a_new;
00425 }
00426 }
00427
00428 function forum_query($query) {
00429 $result = mysql_query($query);
00430 if (mysql_errno()) {
00431 echo "Modul Forum (class.functions.inc.php): Fataler Fehler bei SQL Abfrage aufgetreten!";
00432 $logfile = @fopen(PATH_TO_ROOT."logs/sql-".date("Y-m-d") .".log", "a");
00433 if ($logfile) {
00434 fwrite($logfile, date("H:i:s") ."\n");
00435 fwrite($logfile, "Script: ".$_SERVER["REQUEST_URI"]."\n");
00436 if (isset($_SESSION["userid"])) {
00437 fwrite($logfile, "User: ".$_SESSION["userid"]." (".$_SESSION["username"]."), Course: ".$_SESSION["course"]."\n");
00438 }
00439 fwrite($logfile, "Query: $query\n");
00440 fwrite($logfile, "Error String: ".mysql_error() ."\n");
00441 fwrite($logfile, "Error Number: ".mysql_errno() ."\n\n");
00442 fclose($logfile);
00443 }
00444 } else {
00445 return $result;
00446 }
00447 }
00448 function chopstring($string, $maxchars) {
00449 if (strlen($string) > $maxchars) $string = substr($string, 0, ($maxchars-3)) .'...';
00450 return $string;
00451 }
00452 function updateboard($boardid) {
00453 global $db;
00454
00455 $r_thread = forum_query("SELECT threadid, threadtopic, threadtime, threadlastreplyby FROM forum_thread WHERE threadlink='0' AND boardid='".intval($boardid) ."' GROUP BY threadid ORDER BY threadtime DESC LIMIT 1");
00456 if (mysql_num_rows($r_thread) < 1) {
00457 forum_query("UPDATE forum_board SET
00458 boardlastpost='0',
00459 boardthreadid='0',
00460 boardthreadtopic='',
00461 boardlastpostby='',
00462 boardposts='0',
00463 boardthreads='0'
00464 WHERE boardid='".intval($boardid) ."' AND is_photogallery=1");
00465 } else {
00466 $thread = mysql_fetch_array($r_thread);
00467 $r_thread = forum_query("SELECT COUNT(threadid) AS threadcount, SUM(threadreplies) AS postcount FROM forum_thread WHERE boardid=$boardid");
00468 $thread = array_merge($thread, mysql_fetch_array($r_thread));
00469 $thread['postcount']+= $thread['threadcount'];
00470 forum_query("UPDATE forum_board SET
00471 boardlastpost='$thread[threadtime]',
00472 boardthreadid='$thread[threadid]',
00473 boardthreadtopic='".Data::toMysql($thread['threadtopic'], false) ."',
00474 boardlastpostby='".Data::toMysql($thread['threadlastreplyby'], false) ."',
00475 boardposts='".$thread['postcount']."',
00476 boardthreads='".$thread['threadcount']."'
00477 WHERE boardid='".intval($boardid) ."' AND is_photogallery=0");
00478 }
00479 }
00480 function updatethread($threadid) {
00481
00482 $r_post = forum_query("SELECT posttime, userID, postguestname FROM forum_post WHERE threadid='".intval($threadid) ."' ORDER BY posttime DESC LIMIT 1");
00483 $post = mysql_fetch_array($r_post);
00484 if ($post['userID'] != 0) {
00485 $r_user = forum_query("SELECT username FROM forum_user WHERE userID=$post[userID]");
00486 $user = mysql_fetch_array($r_user);
00487 $author = $user['username'];
00488 if (isset($_SESSION["roleID"])) {
00489 $role = new Role($_SESSION["roleID"]);
00490 $author.= " (".$role->getName($_SESSION["gender"]) .")";
00491 }
00492 if (isset($_SESSION["teamID"])) {
00493 $team = new Team($_SESSION["teamID"]);
00494 $author.= " (".$team->getName() .")";
00495 }
00496 } else {
00497 $author = $post['postguestname'];
00498 }
00499 forum_query("UPDATE forum_thread SET threadtime=$post[posttime], threadlastreplyby='".addslashes($author) ."' WHERE threadid='".intval($threadid) ."'");
00500 }
00501 function checksize($ic_avatar) {
00502 global $err_msg, $config;
00503 if ($ic_avatarsize = @GetImageSize($ic_avatar)) {
00504 if ($ic_avatarsize[0] > $config['avatarwidth']) {
00505 $err_msg.= 'Das Avatar-Bild ist zu breit.<br/>';
00506 }
00507 if ($ic_avatarsize[1] > $config['avatarheight']) {
00508 $err_msg.= 'Das Avatar-Bild ist zu hoch.<br/>';
00509 }
00510 if ($ic_avatarsize[2] > 3) {
00511 $err_msg.= 'Das Avatar-Bild hat ein ungültiges Format.<br/>';
00512 }
00513 } else {
00514 $err_msg.= 'Das Avatar-Bild konnte nicht geladen werden.<br/>';
00515 }
00516 }
00517
00518 function check_banned($text) {
00519 $r_bwords = forum_query("SELECT banword, modword FROM forum_bannedwords");
00520 if (mysql_num_rows($r_bwords) != 0) {
00521 $bwords = array();
00522 $mwords = array();
00523 while (list($bword, $mword) = mysql_fetch_row($r_bwords)) {
00524 $bwords[] = "/([a-z])*(".$bword.")([a-z])*/i";
00525 $mwords[] = $mword;
00526 }
00527 mysql_free_result($r_bwords);
00528 $text = preg_replace($bwords, $mwords, $text);
00529 }
00530 return $text;
00531 }
00532 function compress_page($output) {
00533 global $_SERVER, $config;
00534 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzcompress') && isset($config['compression']) && $config['compression']) {
00535 $output.= '<!-- gzcompress()ed -->';
00536
00537 header('Content-Encoding: gzip');
00538 $size = strlen($output);
00539 $crc = crc32($output);
00540 $output = gzcompress($output, 1);
00541 print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
00542 print substr($output, 0, strlen($output) -4);
00543 print pack('V', $crc);
00544 print pack('V', $size);
00545 } else {
00546 print $output;
00547 }
00548 }
00555 class upload {
00561 function getMaxFileSize() {
00562 global $settings;
00563 if (is_numeric($settings['forum_max_filesize'])) {
00564 $maxFileSize = $settings['forum_max_filesize'];
00565 }
00566 return $maxFileSize;
00567 }
00574 function fileSizeOK($size) {
00575 global $settings;
00576 $ok = true;
00577 if (is_numeric($settings['forum_max_filesize'])) {
00578 $MaxFileSize = $settings['forum_max_filesize'];
00579 if (($size/1024) > $MaxFileSize || (isset($_FILES['userfile']['error']) && $_FILES['userfile']['error'] == UPLOAD_ERR_FORM_SIZE)) $ok = false;
00580 }
00581 return $ok;
00582 }
00589 function fileExtOK($name, $attach = 0) {
00590 global $settings;
00591 if ($settings['forum_forbidden_extensions']) $ForbiddenFileExtensions = $settings['forum_forbidden_extensions'];
00592 $ok = true;
00593 if ($attach) {
00594 if ($ForbiddenFileExtensions) {
00595 $pos = strrpos($name, ".");
00596 if ($pos) $ext = substr($name, $pos+1);
00597 if (isset($ext) && is_array($ForbiddenFileExtensions)) {
00598 foreach($ForbiddenFileExtensions as $value) {
00599 if (strtolower($ext) == strtolower($value)) $ok = false;
00600 }
00601 } elseif (isset($ext) && strtolower($ext) == strtolower($ForbiddenFileExtensions)) $ok = false;
00602 }
00603 } else {
00604 $limitedext = array(".gif", ".jpg", ".jpeg", ".jpe", ".png");
00605 $ext = strtolower(strrchr($name, "."));
00606 (in_array($ext, $limitedext)) ? $ok = true : $ok = false;
00607 }
00608 return $ok;
00609 }
00610 }
00611 ?>